package com.bazaaroid.server.gae.core.persistence.model.partner;

import java.util.HashSet;
import java.util.Set;

import javax.jdo.annotations.Embedded;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;

import com.bazaaroid.server.gae.core.persistence.model.AbstractModel;
import com.google.appengine.api.datastore.GeoPt;
import com.google.appengine.api.datastore.Key;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Location extends AbstractModel {

	@Persistent
	private String name;

	@Persistent(defaultFetchGroup = "true")
	@Embedded
	private Address address;

	@Persistent
	private GeoPt geoPoint;

	@Persistent
	private String imagePath;

	@Persistent
	private String openingHours;

	@Persistent
	private String localId;

	@Persistent
	private Partner partner;

	@Persistent
    private Set<Key> products = new HashSet<Key>();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Address getAddress() {
		return address;
	}

	public void setAddress(Address address) {
		this.address = address;
	}

	public GeoPt getGeoPoint() {
		return geoPoint;
	}

	public float getLongitude() {
		return geoPoint.getLongitude();
	}
	
	public float getLatitude() {
		return geoPoint.getLatitude();
	}
	
	public void setGeoPoint(GeoPt geoPoint) {
		this.geoPoint = geoPoint;
	}

	public String getImagePath() {
		return imagePath;
	}

	public void setImagePath(String imagePath) {
		this.imagePath = imagePath;
	}

	public String getOpeningHours() {
		return this.openingHours;
	}

	public void setOpeningHours(String openingHours) {
		this.openingHours = openingHours;
	}

	public String getLocalId() {
		return localId;
	}

	public void setLocalId(String localId) {
		this.localId = localId;
	}

	public Partner getPartner() {
		return partner;
	}

	public void setPartner(Partner partner) {
		this.partner = partner;
	}

	public Set<Key> getProducts() {
		return products;
	}

	public void setProducts(Set<Key> products) {
		this.products = products;
	}

	public void addProduct(Product product) {
	    products.add(product.getKey());
	    product.getLocations().add(getKey());
	}

	public void removeProduct(Product product) {
		products.remove(product.getKey());
	    product.getLocations().remove(getKey());
	}
}
